package f.app.al;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class Graph extends Activity{
	/*Hello hello */
	Database graphDatabase;
	List<GraphDetails> piedata = new ArrayList<GraphDetails>(0);
	TextView display1, display2, display3, display4;
	String [] expenseList;
	GraphDetails item;
	
	 @Override
	 public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.graph);
	  
	  graphDatabase = new Database(this);
	  Resources res = getResources();
	  expenseList = res.getStringArray(R.array.expenseList);
	  
	  int maxCount = 0;
	  int itemCount = 0;
	  int items[] = {graphDatabase.getCategorySum(0), graphDatabase.getCategorySum(1), graphDatabase.getCategorySum(2), graphDatabase.getCategorySum(3)};
	  int colors[] = { 0xffffff00, 0xff00ffff, 0xff00ff00, 0xffff0000 };
	 
	  for (int i = 0; i < items.length; i++) {
		   itemCount = items[i];
		   item = new GraphDetails();
		   item.count = itemCount;
		   item.label = expenseList[i];
		   item.color = colors[i];
		   piedata.add(item);
		   maxCount = maxCount + itemCount;
	  }

	  display1=(TextView)findViewById(R.id.expList1);
	  display1.setText(expenseList[0]);
	  display1.setTextColor(colors[0]);

	  display2=(TextView)findViewById(R.id.expList2);
	  display2.setText(expenseList[1]);
	  display2.setTextColor(colors[1]);

	  display3=(TextView)findViewById(R.id.expList3);
	  display3.setText(expenseList[2]);
	  display3.setTextColor(colors[2]);
	  
	  display4=(TextView)findViewById(R.id.expList4);
	  display4.setText(expenseList[3]);
	  display4.setTextColor(colors[3]);
	  
	 
	  int OverlayId = R.drawable.gradient;
	  int size = 300;
	  Bitmap mBaggroundImage = Bitmap.createBitmap(size, size,
	    Bitmap.Config.ARGB_8888);
	  
	  ViewGraph viewgraph = new ViewGraph(this);
	  viewgraph.setLayoutParams(new LayoutParams(size, size));
	  viewgraph.setGeometry(size, size, 2, 2, 2, 2, OverlayId);
	  viewgraph.setData(piedata, maxCount);
	  viewgraph.invalidate();
	  viewgraph.draw(new Canvas(mBaggroundImage));
	  viewgraph = null;
	  
	  ImageView mImageView = new ImageView(this);
	  mImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
	    LayoutParams.WRAP_CONTENT));
	  mImageView.setImageBitmap(mBaggroundImage);
	  
	  LinearLayout finalLayout = (LinearLayout) findViewById(R.id.pie_container);
	  finalLayout.addView(mImageView);
		
	}
		protected void onResume() {
			// TODO Auto-generated method stub
			super.onResume();
			graphDatabase = new Database(this);
			graphDatabase.getCategorySum(0); 
			graphDatabase.getCategorySum(1); 
			graphDatabase.getCategorySum(2); 
			graphDatabase.getCategorySum(3);
		}
	 
}